export class ListUtil{
    public static stringToList(str: string) {

        return str?.split(',')
            .map((id) => Number(id))
            .map(idString => Number(idString))
            .filter(idNumber => Number.isInteger(idNumber)) ?? []
    }

    public static listToString(list: Array<number | undefined>) {
        return list.map(idNumber => String(idNumber)).join(',')
    }

    public static stringListToString(list: Array<string | undefined>) {
        return list.join(',')
    }

    public static stringToStringList(str: string) {
        return str?.split(',')
    }

    public static isExistence(item:any,list:Array<any>){
        if (ListUtil.isEmpty(list))
            return false
        return list.indexOf(item) >= 0
    }

    public static haveTheSameItem(list: Array<any>, nowList: Array<any>) {
        if (ListUtil.isEmpty(list) && ListUtil.isEmpty(nowList))
            return false
        for (let item of list){
            console.log(nowList.indexOf(item))
            if (nowList.indexOf(item) >= 0){
                return true
            }
        }
        return false
    }

    public static isEmpty(list?:Array<any>){
        if (!list)
            return true
        return list.length == 0
    }
}